

clear Workspace;
clear Command History;
clear Command Window;
R = 100;
C = 33e-6;
RC = R*C;


Tmod = 10*RC;

T = RC/1000;
t = 0:T:Tmod;
fmin = 2/Tmod;
fmax = 2/T;
f=fmin:((fmax-fmin)/100):fmax;
K = nan(1,length(t));
for j=1:length(f);
    E = A*sin(2*pi*f(j)*t)
    
U=nan(1,length(t));
dU=nan(1,length(t));
U(1)=E(1); dU(1)=0;
U2=U;

for k=2:length(t);
U(k)=U(k-1)*dU(k-1)*T;
dU(k)=(E(k)-U(k))/RC;
U2(k) = (RC*U2(k-1)+E(k)*T)/(RC+T);
end
Us=U(fix(end/2):end);
K(j)=(max(Us)-min(Us))/2;
end

figure;
plot(t,E,t,U,t,U2)
xlabel('t,sec');
ylabel('U,V');